package com.huibeili.web.controller.statistics;


import com.huibeili.order.vo.SkuSaleAmount;
import com.huibeili.statistics.service.StatisticsServiceApi;
import com.huibeili.util.BaseResponse;
import com.huibeili.util.CommonConstant;
import com.huibeili.util.PageHelper;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author 汇贝力 2123957932
 * @date 2019-06-24 20:07
 * <p>
 * 单品销售统计控制器
 */
@RestController
@Api(description = "单品销售统计接口")
public class GoodsSoldController {


    /**
     * 注入统计服务
     */
    @Autowired
    private StatisticsServiceApi statisticsServiceApi;

    /**
     * 分页查询单品销量
     *
     * @param pageHelper 分页帮助类
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @return 单品销量集合
     */
    @GetMapping("/goodssold/salevolume")
    @ApiOperation(value = "分页查询单品销量", notes = "分页查询单品销量（需要认证）")
    @PreAuthorize("hasAuthority('goodssold/queryskusalevolume')")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "int", name = "pageNum", value = "当前页"),
            @ApiImplicitParam(paramType = "form", dataType = "int", name = "pageSize", value = "每页显示的记录数"),
            @ApiImplicitParam(paramType = "form", dataType = "string", name = "startTime", value = "开始时间"),
            @ApiImplicitParam(paramType = "form", dataType = "string", name = "endTime", value = "结束时间"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "单品销量集合", response = SkuSaleAmount.class)
    })
    public BaseResponse querySkuSaleVolume(@ApiIgnore PageHelper<SkuSaleAmount> pageHelper, String startTime, String endTime) {
        return BaseResponse.build(statisticsServiceApi.querySkuSaleVolume(pageHelper, startTime, endTime, CommonConstant.QUERY_WITH_NO_STORE));
    }


    /**
     * 分页查询单品销售额
     *
     * @param pageHelper 分页帮助类
     * @param startTime  开始时间
     * @param endTime    结束时间
     * @return 单品销售额集合
     */
    @GetMapping("/goodssold/saleamount")
    @ApiOperation(value = "分页查询单品销售额", notes = "分页查询单品销售额（需要认证）")
    @PreAuthorize("hasAuthority('goodssold/queryskusaleamount')")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "form", dataType = "int", name = "pageNum", value = "当前页"),
            @ApiImplicitParam(paramType = "form", dataType = "int", name = "pageSize", value = "每页显示的记录数"),
            @ApiImplicitParam(paramType = "form", dataType = "string", name = "startTime", value = "开始时间"),
            @ApiImplicitParam(paramType = "form", dataType = "string", name = "endTime", value = "结束时间"),
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "单品销售额集合", response = SkuSaleAmount.class)
    })
    public BaseResponse querySkuSaleAmout(@ApiIgnore PageHelper<SkuSaleAmount> pageHelper, String startTime, String endTime) {
        return BaseResponse.build(statisticsServiceApi.querySkuSaleAmount(pageHelper, startTime, endTime, CommonConstant.QUERY_WITH_NO_STORE));
    }


}
